package com.farm.controller.user;

import com.farm.entity.Gift;
import com.farm.result.Result;
import com.farm.service.GiftService;
import com.farm.vo.GoodsItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @FileName GiftController
 * @Description
 * @Author Sword
 * @date 2025-02-27
 **/

@RestController("userGiftController")
@RequestMapping("/user/setmeal")
@Slf4j
@Api("根据分类id查询礼盒")
public class GiftController {

    @Autowired
    private GiftService giftService;

    /**
     * 根据分类id查询礼盒
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询礼盒")
    @Cacheable(cacheNames = "giftCache",key = "#categoryId")
    public Result<List<Gift>> list(Long categoryId) {
        log.info("根据分类id查询礼盒:{}", categoryId);
        List<Gift> giftList = giftService.getByCategoryId(categoryId);

        return Result.success(giftList);
    }

    /**
     * 根据礼盒id查询包含的商品
     *
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据礼盒id查询包含的商品")
    public Result<List<GoodsItemVO>> getGoodsById(@PathVariable Long id) {
        log.info("根据礼盒id查询包含的商品:{}", id);
        List<GoodsItemVO> goodsItemVOList = giftService.getGoodsItemById(id);

        return Result.success(goodsItemVOList);
    }
}
